import 'dart:async';
import 'dart:convert';

import 'package:eplorex/models/user/UserBaseInfo.dart';
import 'package:eplorex/providers/user_context.dart';
import 'package:eplorex/utils/HttpUtil.dart';
import 'package:oktoast/oktoast.dart';

import '../models/follow/userprofile_model.dart';

class UserProfileDao {
  static Future<UserProfileModel> queryUserProfile(num userId) async {
    var response = await HttpUtil.getInstance().get(
        "/api/user/relation/v1/profile/query",
        data: {'fromUserId': UserContext.cxt()!.uid, 'toUserId': userId});

    if (response!.statusCode == 200) {
      return UserProfileModel.fromJson(response!.data['data']);
    } else {
      return UserProfileModel();
    }
  }

  static Future<UserBaseInfo> queryCurUserProfile() async {
    var response = await HttpUtil.getInstance()
        .get('/api/user/v1/my/profile/query', data: {
      'userId': UserContext.cxt()!.uid,
    });

    if (response!.statusCode == 200) {
      return UserBaseInfo.fromJson(response!.data['data']);
    } else {
      return UserBaseInfo();
    }
  }

  static Future<void> settingPassword(String oldPassword,String newPassword) async {
    var response = await HttpUtil.getInstance()
        .post('/api/user/v1/setting/password', data: jsonEncode({
      'userId': UserContext.cxt()!.uid,
      'oldPassword':oldPassword,
      'newPassword':newPassword
    }));

    if (response!.statusCode == 200) {
      showToast("设置成功");
    } else {
       showToast("设置失败,请重试");
    }
  }

}
